package com.jugheadzhou.emrpoc.controller;

import com.alibaba.fastjson.JSON;
import com.jugheadzhou.emrpoc.common.Result;
import com.jugheadzhou.emrpoc.model.MedicalRecordTemplate;
import com.jugheadzhou.emrpoc.service.MedicalRecordTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author jugheadzhou
 * @date 2021-10-24
 */
@Slf4j
@RestController
@RequestMapping("/mrTemplate")
public class MedicalRecordTemplateController {

    @Resource
    private MedicalRecordTemplateService medicalRecordTemplateService;

    /**
     * 查询已发布的模板
     *
     * @return
     */
    @GetMapping("listByPublished")
    public Result<?> listByPublished() {
        return Result.success(medicalRecordTemplateService.listByPublished());
    }

    /**
     * 病历模板保存
     *
     * @param medicalRecordTemplate 病历模板对象
     * @return
     */
    @PostMapping("save")
    public Result<?> save(@RequestBody MedicalRecordTemplate medicalRecordTemplate) {
        log.info("病历模板保存开始：{}", JSON.toJSONString(medicalRecordTemplate));
        return Result.success(medicalRecordTemplateService.save(medicalRecordTemplate));
    }

    /**
     * 病历模板删除
     *
     * @param id 病历模板主键ID
     * @return
     */
    @DeleteMapping("delete")
    public Result<?> delete(String id) {
        log.info("病历模板删除开始：{}", id);
        return Result.success(medicalRecordTemplateService.delete(id));
    }
}
